<?php
class CommentsController extends AppController
{
  //var $scaffold;
  var $uses = array("Account", "Category", "Comment", "CookingMethod", "Favorite", "Recipe");
  var $helpers = array("Upload", "Javascript", "Form", "Html", "Ajax", "Teefan");
  var $components = array("RequestHandler");
  
  function post($recipe_permalink = null)
  {
    $recipe = $this->Recipe->findByPermalink($recipe_permalink);
    if ($recipe_permalink == null || !$this->Session->check("Account.logged") || $this->Session->read("Account.logged") == "NO")
    {
      
    }
    else
    {
      if (!empty($this->data))
      {
        //debug($recipe_permalink);
        if (!empty($recipe))
        {
          $this->data["Comment"]["recipe_id"] = $recipe["Recipe"]["id"];
          $this->data["Comment"]["account_id"] = $this->Session->read("Account.id");
          if ($this->Comment->save($this->data))
          {
            $this->data = null;
            $message_done = "Gửi tin nhắn thành công";
            $this->set("message_done", $message_done);
            //$this->redirect("/recipes/show/".$recipe["Recipe"]["permalink"]);
          }
        }
      }
      
    }
    
    $this->set("recipe_permalink", $recipe_permalink);
    $comments = $this->Comment->findAllByRecipeId($recipe["Recipe"]["id"]);
    $this->set("comments", $comments);
  }
}
?>
